/* for save template, load template, and select theme, use the setEntries(ArrayList<String>)
 *  and the setEntryValues(ArrayList<Integer>) to populate their lists
 */
package com.oswego.dawcs;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.text.Editable;
import android.text.InputType;
import android.widget.EditText;

public class Settings extends PreferenceActivity {

	ArrayList<String> cs = new ArrayList<String>();
	ArrayList<String> test = new ArrayList<String>();
	ArrayList<Integer> is = new ArrayList<Integer>();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		PreferenceScreen ps = getPreferenceManager().createPreferenceScreen(
                this);
		test.add("Entry 12");
		test.add("Entry 22");
		test.add("Entry 32");
		cs.add("Entry 1");
		cs.add("Entry 2");
		cs.add("Entry 3");
		is.add(1);
		is.add(2);
		is.add(3);

//        SetIPPreference setIp = new SetIPPreference(this);
//		setIp.setKey("ip");
//		setIp.setTitle("Set DAW IP");

		CustomListPreference selectTheme = new CustomListPreference(this, null);
		selectTheme.setKey("theme");
		selectTheme.setEntries(Theme.getThemeNames());
		selectTheme.setEntryValues(Theme.getThemeIds());
		selectTheme.setDialogTitle("Select Theme");
		selectTheme.setTitle("Select Theme");
		selectTheme.setNegativeButtonText("Cancel");
		selectTheme.setPositiveButtonText("OK");

		ResetPreference reset = new ResetPreference(this);
        reset.setKey("reset");
		reset.setTitle("Reset to Default Number of Channels");

		NumberPickerPreference setDefault = new NumberPickerPreference(this, null);
		setDefault.setKey("default");
		setDefault.setDefaultValue(8);
		setDefault.setMaxValue(16);
		setDefault.setMinValue(0);
		setDefault.setTitle("Set Default Number of Channels");
		setDefault.setDialogTitle("Set Default Number of Channels");

		CheckBoxPreference toggleClick = new CheckBoxPreference(this);
		toggleClick.setKey("click");
		toggleClick.setTitle("Toggle Click");
		toggleClick.setDefaultValue(true);

//		ps.addPreference(setIp);
		ps.addPreference(selectTheme);
		ps.addPreference(reset);
		ps.addPreference(setDefault);
		ps.addPreference(toggleClick);
		setPreferenceScreen(ps);
	}

   /* private class SetIPPreference extends Preference{
        public SetIPPreference(Context context) {
            super(context);
        }
        public void onClick() {
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getContext());
            AlertDialog.Builder alert = new AlertDialog.Builder(
                    this.getContext());

            alert.setTitle("Enter the IP Address of the DAW");

            final EditText input = new EditText(this.getContext());
            input.setInputType(InputType.TYPE_CLASS_PHONE);
            alert.setView(input);

            alert.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            Editable value = input.getText();
                            DAWCS.setDAWIP(value.toString());
                        }
                    });

            alert.setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                        }
                    });

            alert.show();
        }
    }*/

	// This is setup for the reset to default number of channels option
	private class ResetPreference extends Preference {
		public ResetPreference(Context context) {
			super(context);
		}
		public void onClick() {
			SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this.getContext());
            DAWCS.reset = true;
            AlertDialog willReset = new AlertDialog.Builder(this.getContext())
                    .setTitle("Reset")
                    .setMessage("The channel list will reset...")
                    .create();
            willReset.show();
		}

	}
}
